{include file="public/header" /}

<h4 style="border-color-left:#aa6708;">完善个人信息</h4>
<form class="form-inline" style="margin-top:15px;" method="POST" action="{:url('index/member/setting')}">
	<input type="hidden" name="__token__" value="{$token}" />
	<div class="form-group">
		<div class="input-group">
			<div class="input-group-addon">会员昵称</div>
			<input type="text" class="form-control" value="{$member_model->nickname}" disabled readonly>
		</div>
	</div>

	<div class="form-group">
		<div class="input-group">
			<div class="input-group-addon">会员姓名</div>
			<input type="text" name="username" value="{$member_model->username}" class="form-control">
		</div>
	</div>

	<div class="form-group">
		<div class="input-group">
			<div class="input-group-addon">家庭角色</div>
			<select class="form-control" name="gender">
			  <option value="0" {if $member_model->gender eq 0}selected{/if}>皇额娘</option>
			  <option value="1" {if $member_model->gender eq 1}selected{/if}>皇阿玛</option>
			  <option value="2" {if $member_model->gender eq 2}selected{/if}>公公</option>
			</select>
		</div>
	</div>

	<div class="form-group">
		<div class="input-group">
			<div class="input-group-addon">出生年月</div>
			<input type="date" id="birthday" class="form-control" value="{$member_model->birthday!=='0000-00-00'?$member_model->birthday:$today}" name="birthday">
		</div>
	</div>
	<div class="form-group">
		<div class="input-group">
			<div class="input-group-addon">农历生日</div>
			<input type="text" class="form-control" id="nongli" disabled readonly>
		</div>
	</div>

	<button type="button" id="submit" class="btn btn-block btn-info">提交信息</button>
</form>

{include file="public/footer" /}
<script type="text/javascript" src="/static/js/sweetalert.min.js"></script>
<link rel="stylesheet" type="text/css" href="/static/css/sweetalert.css">
<script type="text/javascript">
	$('#birthday').change(function() {
		getDate();
	});

	function getDate() {
		$.getJSON("{:url('index/index/index')}", {"date":$('#birthday').val()}, function(data) {
			$('#nongli').val(data['date']);
		});
	}

	getDate();

	$(document).ready(function(){
		var oldusername = $('form input[name=username]').val(), 
			oldgender = $('form select[name=gender]').val(),
			oldbirthday = $('form input[name=birthday]').val();
		$('#submit').click(function() {
			var form = $('form');

			var newusername = $('form input[name=username]').val(), 
				newgender = $('form select[name=gender]').val(),
				newbirthday = $('form input[name=birthday]').val();

			if(oldusername == newusername && oldgender == newgender && oldbirthday == newbirthday) {
				$.tips({
	                content:'用户信息没有任何改变',
	                stayTime:2000,
	                type:"info"
	            })
				return ;
			}

			$.post(form.attr('action'), form.serializeArray(), function(data) {
				if(data.state ==  false) {
					form.find('input[name=__token__]').val(data.token);
					$.tips({
		                content:data.message,
		                stayTime:2000,
		                type:"warn"
		            })
				} else {
					$.tips({
		                content:data.message,
		                stayTime:2000,
		                type:"success"
		            })
				}
			});
		});
	});
</script>